package com.cameron.servicebase.config.handler;

import com.cameron.servicebase.config.exception.BusinessException;
import com.cameron.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * 全局异常处理
 *
 * @author cameron
 */
@ControllerAdvice
@Slf4j
public class GlobalExceptionHandler {


    @ExceptionHandler(BusinessException.class)
    @ResponseBody
    public Result businessError(BusinessException businessException) {
        log.error(businessException.getMessage());
        return Result.error().message(businessException.getMessage());
    }


    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result error(Exception e) {
        log.error(e.toString());
        return Result.error().message(e.getMessage());
    }

}
